package com.xc.ezplan.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.xc.ezplan.admin.service.AdminAliConfigService;
import com.xc.ezplan.admin.vo.AdminAliConfigVo;
import com.xc.ezplan.core.base.EzResult;
import com.xc.ezplan.log.annotation.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lixingchen
 * @date 2022/12/04
 * @description 阿里云存储
 */
@RestController
@RequestMapping("/ali/config")
@Api(tags = "阿里云存储配置")
@RequiredArgsConstructor
public class AdminAliConfigController {

    private final AdminAliConfigService adminAliConfigService;

    @Log("创建阿里云配置")
    @ApiOperation("创建阿里云配置")
    @PostMapping
    @SaCheckPermission("ali.config.add")
    public EzResult<Object> createConfig(@RequestBody AdminAliConfigVo adminAliConfigVo) {
        adminAliConfigService.createConfig(adminAliConfigVo);
        return EzResult.ok();
    }

    @Log("删除阿里云配置")
    @ApiOperation("删除阿里云配置")
    @DeleteMapping
    @SaCheckPermission("ali.config.delete")
    public EzResult<Object> deleteConfig(@RequestBody List<Long> ids) {
        adminAliConfigService.deleteConfig(ids);
        return EzResult.ok();
    }

    @Log("修改阿里云配置")
    @ApiOperation("修改阿里云配置")
    @PutMapping
    @SaCheckPermission("ali.config.update")
    public EzResult<Object> updateConfig(@RequestBody AdminAliConfigVo adminAliConfigVo) {
        adminAliConfigService.updateConfig(adminAliConfigVo);
        return EzResult.ok();
    }

    @Log("查询阿里云配置")
    @ApiOperation("查询阿里云配置")
    @GetMapping("/{id}")
    public EzResult<Object> queryConfig(@PathVariable Long id) {
        return EzResult.ok(adminAliConfigService.queryConfig(id));
    }

    @Log("按条件查询配置")
    @ApiOperation("按条件查询配置")
    @PostMapping("/all")
    public EzResult<Object> queryAllConfig(@RequestBody(required = false) String keyword) {
        return EzResult.ok(adminAliConfigService.queryAllConfig(keyword));
    }

}
